<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8 ">
<title>Insert title here</title>
<style type="text/css">
table, tr, td {
	border: 2px green solid;
}
</style>
</head>
<body>
	<h1>博文目录</h1><a href="writeArticle.jsp">写文章</a>
	<%
		String sql = "SELECT * FROM article";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			// 加载驱动
			Class.forName("com.mysql.jdbc.Driver");
			// 获得链接
			conn = DriverManager.getConnection("jdbc:mysql://localhost/demo?useSSL=true&"
					+ "user=root&password=root" + "&useUnicode=true&characterEncoding=UTF8");
			// 获得语句对象
			stmt = conn.createStatement();
			// 执行SQL语句

			rs = stmt.executeQuery(sql);
	%>


		<table>
				<tr>
					<td>标题</td>
					<td>文章</td>
					<td>操作</td>
				</tr>

	<%
		while (rs.next()) {
				String title = rs.getString("title");
				String article = rs.getString("article");%>
				
				
				<tr>
					<td><%=title%></td>
					<td><%=article%></td>
					<td><a href="delete.jsp?title=<%=title%>">删除</a></td>
					<td><a href="update.jsp?title=<%=title%>&article=<%=article%>">编辑</a></td>
				</tr>
	<%
		}
	%>
	
	</table>
	
	<%
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (stmt != null) {
				try {
					stmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}

			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	%>

</body>
</html>